package indi.chengx.walty.dirve;
import org.freedesktop.gstreamer.Bin;
import org.freedesktop.gstreamer.Bus.EOS;
import org.freedesktop.gstreamer.Element;
import org.freedesktop.gstreamer.Pipeline;
import org.freedesktop.gstreamer.lowlevel.GstBusAPI;
import org.freedesktop.gstreamer.lowlevel.GstObjectAPI;

import indi.chengx.walty.Config;
import indi.chengx.walty.util.Console;

public class Camera implements CameraListener{
	private final String TAG = this.getClass().getSimpleName();
	private Pipeline pipe;
	private Bin bin;
	
	public Camera() {
		pipe = Pipeline.launch(Config.LAUNCH_COMMAND);
		//GstBusAPI.GSTBUS_API.gst_bus_add_watch(pipe.getBus(), function, data)
		//GstBusAPI.GSTBUS_API.gst_bus_add_signal_watch(pipe.getBus());
		CameraCallback cc = new CameraCallback(pipe);
		pipe.getBus().connect(cc);
		Element tcam = pipe.getElementByName("src");
		//Console.log(TAG, tcam.get("Exposure_Auto").toString());
		//Console.log(TAG, tcam.getPropertyDefaultValue("Exposure_Auto").toString());
		//GstBusAPI.GSTBUS_API.gst_bus_add_watch(pipe.getBus(),cc, null);
		
		//GstObjectAPI.GSTOBJECT_API.gst_object_unref(pipe.getBus());
		//GstBusAPI.GSTBUS_API.gst_bus_set_sync_handler(pipe.getBus(), new CameraCallback(pipe), null,null);
	}

	public Pipeline getPipe() {
		return pipe;
	}

	public void playVideo() {
		// TODO Auto-generated method stub
		pipe.ready();
		pipe.getElementByName("valve").set("drop", false);
		pipe.play();
	}

	public void readyVideo() {
		// TODO Auto-generated method stub
		pipe.getElementByName("valve").set("drop", false);
		pipe.ready();
	}


	public void pauseVideo() {
		// TODO Auto-generated method stub
		pipe.ready();
	}


	public void close() {
		// TODO Auto-generated method stub
		pipe.stop();
	}


	public void takePicture() {
		// TODO Auto-generated method stub
		pipe.getElementByName("valve").set("drop", false);
	}
	
}
